﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irony.Ast;
using Irony.Interpreter;
using Irony.Parsing;

namespace ConciseMarkupLanguage.Ast
{
    class AttrNode : AstNode
    {
        string _key;
        AstNode _value;

        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);
            _key = AsString = treeNode.ChildNodes[0].FindTokenAndGetText();
            _value = AddChild("value", treeNode.ChildNodes.Last());
        }

        public override void EvaluateNode(EvaluationContext context, AstMode mode)
        {
            _value.Evaluate(context, AstMode.Read);
            context.Data.Push(new KeyValuePair<string, object>(_key, context.Data.Pop()));
        }
    }
}
